package com.liming.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.liming.model.Comment;
import com.liming.service.CommentService;

@WebServlet("/Comment")
public class CommentServlet extends HttpServlet {
	
	CommentService cs = new CommentService();
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String method = (String)request.getParameter("method");
		if(method.equals("getAllComment")){
			getAllComment(request,response);
		}
		
	}

	//获取全部评论
	private void getAllComment(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		int goodsid = Integer.parseInt(request.getParameter("goodsid"));
		
		List<Comment> comments= cs.getAllComment(goodsid);
		
		request.setAttribute("Comments", comments);
		//显示评论 #.jsp
		request.getRequestDispatcher("#.jsp").forward(request, response);
	}
}
